/**
 * 
 */
package com.gmail.blackdog1987.carcare.web.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gmail.blackdog1987.carcare.service.MaintainService;
import com.gmail.blackdog1987.carcare.service.ShopService;
import com.gmail.blackdog1987.carcare.util.ErrorCode;
import com.gmail.blackdog1987.carcare.web.dto.JsonResult;

/**
 * 
 * @author 董国超
 *
 */
@Controller
public class ShopController extends BaseController {
	@Autowired
	private ShopService shopService;
	@Autowired
	private MaintainService maintainService;

	@ResponseBody
	@RequestMapping(value = "maintainlist", method = RequestMethod.POST)
	public JsonResult maintainlist(@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = maintainService.getList(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}

	@ResponseBody
	@RequestMapping(value = "maintaindetaillist", method = RequestMethod.POST)
	public JsonResult maintaindetaillist(
			@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = maintainService.getDetailList(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}

	@ResponseBody
	@RequestMapping(value = "driveschool", method = RequestMethod.POST)
	public JsonResult driveschool(@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = shopService.getDriveSchool(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}

	@ResponseBody
	@RequestMapping(value = "cleanshop", method = RequestMethod.POST)
	public JsonResult cleanshop(@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = shopService.getCleanShop(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}
	
	@ResponseBody
	@RequestMapping(value = "cleanshopdetail", method = RequestMethod.POST)
	public JsonResult cleanshopdetail(@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = shopService.getCleanShopDetail(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}

	@ResponseBody
	@RequestMapping(value = "carfixshop", method = RequestMethod.POST)
	public JsonResult carfixshop(@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = shopService.getFixShop(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}

	@ResponseBody
	@RequestMapping(value = "carchangeshop", method = RequestMethod.POST)
	public JsonResult carchangeshop(@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = shopService.getChangeShop(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}

	@ResponseBody
	@RequestMapping(value = "carchangeshopdetail", method = RequestMethod.POST)
	public JsonResult carchangeshopdetail(
			@RequestParam Map<String, String> filter,
			HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = shopService.getChangeDetail(filter);
		if (!ErrorCode.NO.equals(result.get("code").toString())) {
			return new JsonResult(Boolean.FALSE, result.get("code").toString(),
					result.get("msg") == null ? "" : result.get("msg")
							.toString(), null);
		}
		return new JsonResult(Boolean.TRUE, result.get("result"));
	}
}
